package com.tms.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tms.springboot.aggregation.pojo.PdFleet;
import com.tms.springboot.base.pojo.PdTruckDriver;
import com.tms.springboot.base.pojo.PdTruckDriverLicense;
import com.tms.springboot.mapper.PdTruckDriverMapper;
import com.tms.springboot.service.PdTruckDriverService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tms.springboot.vo.PdTruckDriverBasicInfoVo;
import com.tms.springboot.vo.PdTruckDriverInfoVo;
import com.tms.springboot.vo.PdTruckDriverVo;
import com.tms.springboot.vo.PdTruckVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 司机表 服务实现类
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@Service
public class PdTruckDriverServiceImpl extends ServiceImpl<PdTruckDriverMapper, PdTruckDriver> implements PdTruckDriverService {

    @Autowired
    PdTruckDriverMapper mapper;
    @Override
    public PdTruckDriver queryDriverByUserIdService(String userId) {
        return this.mapper.queryDriverByUserId(userId);
    }

    @Override
    public PageInfo<PdTruckDriverInfoVo> queryDriverInfoService(PdTruckDriverVo pdTruckDriverVo) {
        if (ObjectUtils.isEmpty(pdTruckDriverVo)){
            throw new IllegalArgumentException("pdTruckDriverVo is empty");
        }

        PageHelper.startPage(pdTruckDriverVo.getCurrentPage(), pdTruckDriverVo.getPageSize());
        List<PdTruckDriverInfoVo> pdTruckDriverInfoVos = this.mapper.queryDriverInfo(pdTruckDriverVo);

        PageInfo<PdTruckDriverInfoVo> pageInfo = new PageInfo<>(pdTruckDriverInfoVos);

        return pageInfo;
    }

    @Override
    public PdTruckDriverBasicInfoVo queryDriverBasicInfoByIdService(String id) {
        return this.mapper.queryDriverBasicInfoById(id);
    }

    @Override
    public PdTruckVo queryTruckByIdService(String id) {
        return this.mapper.queryTruckById(id);
    }

    @Override
    public PdTruckDriverLicense queryLicenseByUserIdService(String id) {
        return this.mapper.queryLicenseByUserId(id);
    }

    @Override
    public Boolean updLicenseByIdService(PdTruckDriverLicense pdTruckDriverLicense) {
        return this.mapper.updLicenseById(pdTruckDriverLicense);
    }

}
